package com.hhkj.payment.wechat.common.component.provider;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.refund.RefundService;

/**
 * ServiceProvider
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/11/14 18:23
 */
public class ServiceProvider {


    /** jsapi_Service */
    private static JsapiService jsapiService;

    /** jsapi_Service_Extension */
    private static JsapiServiceExtension jsapiServiceExtension;

    /** refund_Service */
    private static RefundService refundService;

    /** 获取 jsapi_Service */
    public synchronized static JsapiService getJsapiService() {
        if (jsapiService == null) {
            // 初始化商户配置
            Config config = ConfProvider.getRSAAutoCertificateConfig();
            jsapiService = new JsapiService.Builder().config(config).build();
        }
        return jsapiService;
    }

    /** 获取 jsapi_Service_Extension */
    public synchronized static JsapiServiceExtension getJsapiServiceExtension() {
        if (jsapiServiceExtension == null) {
            Config config = ConfProvider.getRSAAutoCertificateConfig();
            jsapiServiceExtension = new JsapiServiceExtension.Builder().config(config).build();
        }
        return jsapiServiceExtension;
    }

    /** 获取 refund_Service */
    public synchronized static RefundService getRefundService() {
        if (refundService == null) {
            Config config = ConfProvider.getRSAAutoCertificateConfig();
            refundService = new RefundService.Builder().config(config).build();
        }
        return refundService;
    }
}
